console.log('1111')
const express = require('express')
const axios = require('axios')

const app = express()
app.use(express.urlencoded({ extended: false })) // 现在就方便多了，express的两个方法一执行就行啦
app.use(express.json())
app.use(function (req, res, next) {
  console.log(req.url.split('/'))
  console.log(req.query)
  const urllist = req.url.split('/')
  if (!req.user) return next()
  const roleId = req.user.roleId
  const sql = `select * from ev_role where roleId=?`
  db.query(sql, roleId, (err, rel) => {
    if (err) return res.cc(err)
    // if (rel.length === 1) return res.cc('该列表无权限访问')
    let rol = eval('(' + rel[0].menuIds + ')')
    rol.push('my')
    const bol = rol.some((item) => {
      return urllist.some((items) => items === item)
    })
    if (bol) return next()
    if (!bol) return res.cc('没有权限')
  })
})
app.listen(3000, () => {
  console.log('http://127.0.0.1:3000')
})
